package tools;

import java.awt.*;
import javax.swing.*;

/**
 * Title:
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class HtmlExtractorProcess extends JPanel {
  private static final int MAIN_ROW = 2;

  private static final int URL_COL = 0;
  private static final int HTML_COL = URL_COL + 2;
  private static final int HTML_TRANS_COL = HTML_COL + 2;
  private static final int XHTML_COL = HTML_TRANS_COL + 2;
  private static final int XSL_COL = XHTML_COL + 2;
  private static final int XSL_TRANS_COL = XSL_COL;
  private static final int XML_COL = XSL_COL + 2;

  public HtmlExtractorProcess() {
    setLayout( new GridBagLayout() );
    setOpaque( false );

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.anchor = gbc.CENTER;

    gbc.gridx = URL_COL;
    gbc.gridy = MAIN_ROW;
    JButton urlButton = new JButton( "URL" );
    add( urlButton, gbc );

    gbc.gridx = HTML_COL;
    gbc.gridy = MAIN_ROW;
    JButton htmlButton = new JButton( "HTML" );
    add( htmlButton, gbc );

    gbc.gridx = HTML_TRANS_COL;
    gbc.gridy = MAIN_ROW;
    JComponent htmlXhtmlLabel = makeTranslateLabel( "HTML to XHTML" );
    add( htmlXhtmlLabel, gbc );

    gbc.gridy = MAIN_ROW - 2;
    JButton logButton = new JButton( "Log" );
    add( logButton, gbc );

    gbc.gridx = XHTML_COL;
    gbc.gridy = MAIN_ROW;
    JButton xhtmlButton = new JButton( "XHTML" );
    add( xhtmlButton, gbc );

    gbc.gridx = XSL_COL;
    gbc.gridy = MAIN_ROW - 2;
    JButton xslButton = new JButton( "XSL" );
    add( xslButton, gbc );

    gbc.gridx = XSL_TRANS_COL;
    gbc.gridy = MAIN_ROW;
    JComponent xhtmlXmlLabel = makeTranslateLabel( "XHTML to XML" );
    add( xhtmlXmlLabel, gbc );

    gbc.gridx = XML_COL;
    gbc.gridy = MAIN_ROW;
    JButton xmlButton = new JButton( "XML" );
    add( xmlButton, gbc );

    gbc.weightx = .5;
    gbc.weighty = 0;
    gbc.gridx = URL_COL + 1;
    gbc.gridy = MAIN_ROW;
    gbc.fill = gbc.HORIZONTAL;
    ProcessFlow urlFlow = new ProcessFlow( urlButton, htmlButton );
    add( urlFlow, gbc );

    gbc.gridx = HTML_COL + 1;
    gbc.gridy = MAIN_ROW;
    gbc.fill = gbc.HORIZONTAL;
    ProcessFlow htmlXhtmlInFlow = new ProcessFlow( htmlButton, xhtmlButton );
    add( htmlXhtmlInFlow, gbc );

    gbc.gridx = HTML_TRANS_COL + 1;
    gbc.gridy = MAIN_ROW;
    gbc.fill = gbc.HORIZONTAL;
    ProcessFlow htmlXhtmlOutFlow = new ProcessFlow( htmlXhtmlLabel, xhtmlButton );
    add( htmlXhtmlOutFlow, gbc );

    gbc.gridx = XHTML_COL + 1;
    gbc.gridy = MAIN_ROW;
    gbc.fill = gbc.HORIZONTAL;
    ProcessFlow xhtmlFlow = new ProcessFlow( xhtmlButton, xhtmlXmlLabel );
    add( xhtmlFlow, gbc );

    GridBagConstraints gl = (GridBagConstraints)gbc.clone();
    gl.gridx = XSL_TRANS_COL + 1;
    gl.gridy = MAIN_ROW;
    gl.fill = gbc.HORIZONTAL;
    ProcessFlow xmlFlow = new ProcessFlow( xhtmlXmlLabel, xmlButton );
    add( xmlFlow, gl );

    gbc.weightx = 0;
    gbc.weighty = .5;
    gbc.gridx = XSL_COL ;
    gbc.gridy = MAIN_ROW - 1;
    gbc.fill = gbc.VERTICAL;
    ProcessFlow xslFlow = new ProcessFlow( xslButton, xhtmlXmlLabel );
    add( xslFlow, gbc );

    gbc.gridx = HTML_TRANS_COL;
    gbc.gridy = MAIN_ROW - 1;
    ProcessFlow xhtmlLogFlow = new ProcessFlow( htmlXhtmlLabel, logButton );
    add( xhtmlLogFlow, gbc );

  }

  static public JComponent makeTranslateLabel( String name ){
    JPanel p = new JPanel( new BorderLayout() );
    p.add( new JLabel( name, JLabel.CENTER ), BorderLayout.NORTH );
    p.add( new JLabel( "Translation", JLabel.CENTER ), BorderLayout.SOUTH );
    p.setOpaque( false );
    return p;
  }
}